package yl.hs.bmipfull.controllers.salemanage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.salemanage.IContractProductPriceAdjustService;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/*
 * ContractProductPriceAdjustController
 * @category
 * @author 谢景广
 * @date 2022-10-13
 */
@Api(value = "销售合同信息价调价信息Web接口", tags = "销售管理——销售合同信息价调价")
@RestController
@RequestMapping("/api/contract/product/price/adjust/")
public class ContractProductPriceAdjustController extends ControllerBase {
    @ApiOperation(value = "获取最新的调价信息",notes = "根据合同编号获取合同的最新信息价条件信息")
    @GetMapping("/last/{contractSN}")
    public WebResult getLastAdjustRecord(@ApiParam(value = "合同编号") @PathVariable String contractSN){
        try{
            var lastRecord = service.findContractAdjust(contractSN);
            return success("ok",lastRecord);
        }
        catch (Exception ee){
            return error(ee);
        }
    }
    @ApiOperation(value = "获取合同的所有信息价调整信息",notes = "根据合同编号获取合同的所有信息价调整信息")
    @GetMapping("/list/{contractSN}")
    public WebResult getContractRecord(@ApiParam(value = "合同编号") @PathVariable String contractSN){
        try{
            var recordList = service.queryContractAdjust(contractSN);
            return success("ok",recordList);
        }
        catch (Exception ee){
            return error(ee);
        }
    }

    @ApiOperation(value = "保存合同的信息价调整信息",notes = "保存合同的信息价调整信息")
    @PostMapping("/save")
    public WebResult saveContractAdjust(@RequestBody SubmitModel model){
        try{
            var result = service.saveModel(model);
            if(result>0)
                return success("ok");
            else
                return fail("数据未保存");
        }
        catch (Exception ee){
            return error(ee);
        }
    }

    private IContractProductPriceAdjustService service;

    @Autowired
    public void setService(IContractProductPriceAdjustService service) {
        this.service = service;
    }
}
